package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberDao;
import com.xrit.sunnyday.dao.OrderDao;
import com.xrit.sunnyday.service.ReportService;
import com.xrit.sunnyday.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService{

    @Autowired
    MemberDao memberDao;

    @Autowired
    OrderDao orderDao;

    /**
     * 运营统计数据
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //获取当前的日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月的第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        // =================== 会员统计 ======================
        //今日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        // ===============  预约统计 ===================
        //今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        //今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        // ============== 热门套餐 ==================
        //热门套餐（取前4）
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map<String, Object> map = new HashMap<>();
        map.put("reportDate",today); //当前时间
        map.put("todayNewMember",todayNewMember); //今日新增会员数
        map.put("totalMember",totalMember); //总会员数
        map.put("thisWeekNewMember",thisWeekNewMember); //本周新增会员数
        map.put("thisMonthNewMember",thisMonthNewMember); //本月新增会员数
        map.put("todayOrderNumber",todayOrderNumber); //今日预约数
        map.put("thisWeekOrderNumber",thisWeekOrderNumber); //今日到诊数
        map.put("thisMonthOrderNumber",thisMonthOrderNumber); //本周预约数
        map.put("todayVisitsNumber",todayVisitsNumber); //本周到诊数
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber); //本月预约数
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber); //本月到诊数
        map.put("hotSetmeal",hotSetmeal); //热门套餐
        return map;
    }
}
